﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace comm
{
    public partial class mailsend : Form
    {
        public mailsend()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            sendmail("18664000308@163.com", this.textBox1.Text.Trim(), this.textBox2.Text, this.textBox3.Text);
        }

        public void sendmail(string senduser, string recuser, string sub, string str)
        {
            if (senduser != null && recuser != null)
            {
                //设置smtp服务器,以及登陆账号密码
                System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.163.com");
                smtp.Credentials = new System.Net.NetworkCredential("18664000308@163.com", "603505");
                smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(senduser, recuser, sub, str);
                msg.BodyEncoding = System.Text.Encoding.UTF8;
                msg.IsBodyHtml = true;

                try
                {
                    smtp.Send(msg);
                }
                catch (Exception err)
                {
                    return;
                }
            }
            else
                return;
        }

    }
}
